package PriorityQueueDeom;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-03-28
 * Time: 21:27
 */
class Imp implements Comparator<Integer> {

    //通过自己建一个比较器来将小堆转化为大堆
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class PrioQueue {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<>();
        priorityQueue1.offer(1);
        priorityQueue1.offer(2);
        System.out.println("======");
        Imp imp = new Imp();
        PriorityQueue<Integer> priorityQueue2= new PriorityQueue<>(imp);
        /*priorityQueue2.offer(1);
        priorityQueue2.offer(2);
        System.out.println("=========");*/



        //最小K个数
       /* public int[] smallestK(int[] arr, int k) {
            int[] tmp = new int[k];
            if (k == 0) {
                return tmp;
            }
            Imp imp = new Imp();
            PriorityQueue<Integer> maxHeap = new PriorityQueue<>(imp);
            // 建立大堆含k个元素
            for (int i = 0; i < k; i++) {
                maxHeap.offer(arr[i]);
            }
            // 从第k个元素遍历
            for (int j = k; j < arr.length; j++) {
                // 堆顶元素小于数组下标j的大小
                if (arr[j] < maxHeap.peek()) {
                    maxHeap.poll();
                    maxHeap.offer(arr[j]);
                }
            }
            // 打印这个大堆中的元素
            for (int i = 0; i < tmp.length; i++) {
                tmp[i] = maxHeap.poll();
            }
            return tmp;
        }*/
    }
}
